<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="/lib/layui/css/modules/laydate/default/laydate.css"  media="all">
  <link rel="stylesheet" href="/lib/layui/css/modules/layer/default/layer.css"  media="all">
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
  <div class="layuimini-main">

    <fieldset class="table-search-fieldset">
      <legend>搜索信息</legend>
      <div style="margin: 10px 10px 10px 10px">
        <form class="layui-form layui-form-pane" action="">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">登录号</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="id" id="id" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">书名</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="name" id="name" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">别名</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="alias" id="alias" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">作者</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="author" id="author" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">ISBN</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="ISBN" id="ISBN" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">中图号</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="classification" id="classification" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">出版社</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="publishingHouse" id="publishingHouse" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">出版年份</label>
              <div class="layui-input-inline">
                <input class="layui-input" name="publishDate" id="publishDate" autocomplete="off">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">起始日期</label>
              <div class="layui-input-inline">
                <input type="text" name="dateStart" id="dateStart" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">结束日期</label>
              <div class="layui-input-inline">
                <input type="text" name="dateEnd" id="dateEnd" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <button type="button" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn" id="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
            </div>
          </div>
        </form>
      </div>
    </fieldset>

    <script type="text/html" id="toolbarDemo">
      <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 录入图书 </button>
      </div>
    </script>
    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <script type="text/html" id="currentTableBar">
      <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="update">信息修改</a>
      <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
    </script>

  </div>
</div>
<script>
  layui.use(['form', 'table','miniPage','element','laydate'], function () {
    var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            laydate = layui.laydate;
    laydate.render({
      elem: '#dateStart',
    });
    laydate.render({
      elem: '#dateEnd',
    });
    form.render();
    table.render({
      elem: '#currentTableId',
      url: '/bookInfo',
      toolbar: '#toolbarDemo',
      defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示',
        layEvent: 'LAYTABLE_TIPS',
        icon: 'layui-icon-tips'
      }],
      cols: [
        [
          {field: 'id', title: '登录号', sort: true},
          {field: 'name', title: '书名', sort: true},
          {field: 'alias', title: '别名', sort: true},
          {field: 'author', title: '作者', sort: true},
          {field: 'classification', title: '中图号', sort: true},
          {field: 'publishingHouse',title: '出版社', sort: true},
          {field: 'publishDate', title: '出版时间', sort: true},
          {field: 'date', title: '上架时间', sort: true},
          {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
        ]
      ],
      limit: 15,
      page: true,
      skin: 'line'
    });

    layui.$('#data-search-btn').on('click',function () {
      //console.log(data.field)
      var id = document.getElementById('id').value,
              name = document.getElementById('name').value,
              ISBN = document.getElementById('ISBN').value,
              alias = document.getElementById('alias').value,
              classification = document.getElementById('classification').value,
              author = document.getElementById('author').value,
              dateStart = document.getElementById('dateStart').value,
              dateEnd = document.getElementById('dateEnd').value,
              publishDate = document.getElementById('publishDate').value,
              publishingHouse = document.getElementById('publishingHouse').value;
      //执行搜索重载
      table.reload('currentTableId', {
        page: {
          curr: 1
        }
        , where: {
          'id':id,
          'ISBN':ISBN,
          'alias':alias,
          'classification':classification,
          'dateStart':dateStart,
          'dateEnd':dateEnd,
          'publishDate':publishDate,
          'author': author,
          'name': name,
          'publishingHouse' : publishingHouse
        }
      });

      return false;
    });

    /**
     * toolbar事件监听
     */
    table.on('toolbar(currentTableFilter)', function (obj) {
      if (obj.event === 'add') {   // 监听添加操作
        var content = miniPage.getHrefContent('/admin/addBook.html');
        var index = layer.open({
          title: '添加学生',
          type: 1,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['85%','75%'],
          content: content,
        });
        $(window).on("resize", function () {
          layer.full(index);
        });
      } else if (obj.event === 'delete') {  // 监听删除操作
        var checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      }
    });
    table.on('tool(currentTableFilter)', function (obj) {
      var data = obj.data;
      if (obj.event === 'delete') {
        layer.confirm('<div class="layui-inline">\n' +
                '      <label class="layui-form-label">验证密码</label>\n' +
                '      <div class="layui-input-inline">\n' +
                '        <input type="password" name="pwd" id="pwd" lay-verify="required" autocomplete="off" class="layui-input">\n' +
                '      </div>\n' +
                '    </div>', function (index) {
          $.ajax({
            url: '/deleteBook',
            type:'POST',
            data:{
              id:data.id,
              pwd:document.getElementById('pwd').value
            },
            success:function (res){
              if(res.code==200){
                layer.close(index);
                layer.msg("删除成功!");
                table.reload('currentTableId');
              }else {
                layer.msg(res.msg);
              }
            }

          })
        });
        return false;
      }else if (obj.event === 'update') {
        var content = miniPage.getHrefContent('/updateBook?id='+data.id);
        var index = layer.open({
          title: data.name,
          type: 1,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['85%','75%'],
          content: content,
        });
        $(window).on("resize", function () {
          layer.full(index);
        });
        return false;
      }
      return false;
    });

  });
</script>
</body>
</html>

